from django.contrib import admin
from files.models import File, FilePath

from jobs.models import Job

def File_analyze(modeladmin, request, queryset):
  for object in queryset.exclude(hash=None):
    j = Job.objects.create_job(object, 'analyze')
    j.schedule()
    j.save()
File_analyze.short_description = "Analyze selected files"

class FileAdmin(admin.ModelAdmin):
    actions = [File_analyze]
    list_display = ('id', 'file_name', 'location', 'hash', 'version', 'author', )
    list_filter = ('author',)
    search_fields = ('file_name', 'hash', )
    raw_id_fields = ('ancestor',)

admin.site.register(File, FileAdmin)

admin.site.register(FilePath)
